package com.laoli.springcloud.controller;

import com.laoli.springcloud.entities.CommonResult;
import com.laoli.springcloud.entities.Payment;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@Log4j2
public class PaymentController {


    @Autowired
    RestTemplate restTemplate;

    public  static  final  String  PAYMENT_URL="http://CLOUD-PAYMENT-SERVICE";

    @RequestMapping("/consum/payment/create")
    public CommonResult<Payment> payment(Payment payment){

        return   restTemplate.postForObject(PAYMENT_URL+"/payment/create", payment, CommonResult.class);
    }


    @GetMapping("/consum/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id){

        ResponseEntity<CommonResult> forEntity = restTemplate.getForEntity(PAYMENT_URL + "/payment/get/{id}", CommonResult.class,id);

        CommonResult body = forEntity.getBody();

        return body;

    }




}
